﻿function CheckLogin()
{
    $(":submit,:button,:reset").attr("disabled", true);
    var loginName = $("#LoginName").val();
    var loginPwd = $("#LoginPwd").val();
    if (loginName == "")
    {
        alert("请输入用户名！");
        $("#LoginName").focus();
        return;
    }
    if (loginPwd == "")
    {
        alert("请输入密码！");
        $("#LoginPwd").focus();
        return;
    }
    $.ajax({
        url: "/Actions/Login.ashx?method=CheckLogin&LoginName=" + loginName + "&LoginPwd=" + loginPwd + "&rnd=" + Math.random(),
        type: "get",
        //  datatype: "text",
        success: function (data)
        {
            if (data)
            {
                var jobj = $.parseJSON(data);
                if (jobj.status)
                {
                    $.cookie("UserId", jobj.message.UserId, { path: '/', expires: 1 });
                    $.cookie("RealName", jobj.message.RealName, { path: '/', expires: 1 });
                    $.cookie("RoleId", jobj.message.RoleId, { path: '/', expires: 1 });
                    $.cookie("RoleName", jobj.message.RoleName, { path: '/', expires: 1 });
                    $.cookie("LoginTime", jobj.message.LoginTime, { path: '/', expires: 1 });
                    window.location.href = "/Admin/Index.html";
                }
                else
                {
                    alert(jobj.message);
                    $(":submit,:button,:reset").attr("disabled", false);
                }
            }
        }
    });
}
function Cancel()
{
    $("#LoginName").val("");
    $("#LoginPwd").val("");
    $("#LoginName").focus();
}
